/*
 * Translated default messages for the jQuery validation plugin.
 * Locale: ZH (Chinese, 中文 (Zhōngwén), 汉语, 漢語)
 */
$.extend( $.validator.messages, {
	required: "这是必填字段",
	remote: "请修正此字段",
	email: "请输入有效的电子邮件地址",
	url: "请输入有效的网址",
	date: "请输入有效的日期",
	dateISO: "请输入有效的日期 (YYYY-MM-DD)",
	number: "请输入有效的数字",
	digits: "只能输入数字",
	creditcard: "请输入有效的信用卡号码",
	equalTo: "你的输入不相同",
	extension: "请输入有效的后缀",
	maxlength: $.validator.format( "最多可以输入 {0} 个字符" ),
	minlength: $.validator.format( "最少要输入 {0} 个字符" ),
	rangelength: $.validator.format( "请输入长度在 {0} 到 {1} 之间的字符串" ),
	range: $.validator.format( "请输入范围在 {0} 到 {1} 之间的数值" ),
	max: $.validator.format( "请输入不大于 {0} 的数值" ),
	min: $.validator.format( "请输入不小于 {0} 的数值" )
} );

//联系电话(手机/电话皆可)验证 
jQuery.validator.addMethod("isPhone", function(value,element) { 
	var length = value.length; 
	var mobile = /^1\d{10}$/; 
	var tel = /^\d{3,4}-?\d{7,9}$/; 
	return this.optional(element) || (tel.test(value) || mobile.test(value)); 
}, "请填写正确的联系电话");

//手机号码验证 
jQuery.validator.addMethod("isMobile", function(value, element) {
	var length = value.length;
	var mobile = /^1\d{10}$/;
	return this.optional(element) || (length == 11 && mobile.test(value));
}, "请填写正确的手机号码");

//邮政编码验证 
jQuery.validator.addMethod("isZipCode", function(value, element) { 
	var tel = /^[0-9]{6}$/; 
	return this.optional(element) || (tel.test(value)); 
}, "请填写正确的邮政编码");

//身份证号码验证 
jQuery.validator.addMethod("isIdCard", function(value, element) {
	var reg = /^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/;
	return this.optional(element) || (reg.test(value));
}, "请填写正确的身份证号码"); 

//上传文件图片验证 
$.validator.addMethod("isImg", function(value, element, param) {
	return this.optional(element) || function(val){
		console.debug(val);
		var arrs = val.split('.');
		if(arrs.length < 2) return false;
		
		var suffix = arrs[arrs.length - 1].toLowerCase();
		return (suffix == 'jpg' || suffix == 'jpeg' || suffix == 'png' || suffix == 'bmp' || suffix == 'gif');
	}(value);   
}, "请上传图片文件");